#include "UartWorker.h"
#include "QSerialPort"
#include "QSerialPortInfo"
#include "QtDebug"


UartWorker::UartWorker(QObject *parent) : QThread(parent)
{
    m_run_flag = true;
}

void UartWorker::run()
{
    QString result="12345";

    QList<QSerialPortInfo> InfoList = QSerialPortInfo::availablePorts();
//    qDebug()<<InfoList;
    m_PortName = InfoList.at(0).portName();
    QSerialPort *Port = new QSerialPort(InfoList.at(0));
    Port->setParity((QSerialPort::Parity)5);
    Port->setBaudRate(1024*1024*100);
    Port->setDataBits((QSerialPort::DataBits)1);

    qDebug()<<Port->open(QIODevice::ReadWrite);
    qDebug()<<m_PortName;

    while (m_run_flag) {
        if(Port->waitForReadyRead(1)>0)
        {
            QByteArray array = Port->readAll();
            if(array.size())
                qDebug()<<array.size();
        }
    }
}

void UartWorker::setRunState(bool flag)
{
    m_run_flag = flag;
}
